<?php

/**
 * skill actions.
 *
 * @package    jiazhang
 * @subpackage skill
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class skillActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
        $page = (int)$request->getParameter('page',1);
        $category = (int)$request->getParameter('category',0);
        
        if($category == 0){
            $dql = Doctrine::getTable('NewSkill')->createQuery()->orderBy('created_at desc');
        }else{
            $dql = Doctrine::getTable('NewSkill')->createQuery()->where('category = ?',$category)->orderBy('created_at desc');
        }
        
        $this->pager = new sfDoctrinePager('NewSkill',30);
        $this->pager->setQuery($dql);
        $this->pager->setPage($page);
        $this->pager->init();
  }
  
  public function executeShow(sfWebRequest $request){
      $skill_id = (int)$request->getParameter('id',0);
      $this->forward404Unless($this->skill = Doctrine::getTable('NewSkill')->findOneById($skill_id));
      
  }
  
  public function executeChange_status(sfWebRequest $request){
      if($request->isMethod('POST')){
          $skill_id = (int)$request->getParameter('id',0);
          $this->forward404Unless($skill = Doctrine::getTable('NewSkill')->findOneById($skill_id));
          $status = (int)$request->getParameter('status',0);
          $skill->setStatus($status)->save();
          $this->getUser()->setFlash('success', '状态更改成功！');
          $this->redirect($request->getReferer());
      }
  }
  
  
}
